#include "common.h"
#include "alloc.h"
#include "stdio.h"

typedef struct{
	int *base;
	int front;
	int rear;
	int size;
}IntQueue;

int addone(int i,int size)
{
 return (i+1)%size;
}

void InitIntQueue(IntQueue *pq,int s)
{
	pq->base=(int *)malloc(sizeof(int)*(s+1));
	if(!pq->base)
		return;

	pq->front=pq->rear=0;
	pq->size=s+1;
}

void DestoryIntQueue(IntQueue *pq)
{
	free(pq->base);
}

Status EnIntQueue(IntQueue *pq,int e)
{
	if(addone(pq->rear,pq->size)==pq->front)
		return ERROR;
	(pq->base)[pq->rear]=e;
	pq->rear=addone(pq->rear,pq->size);
	return OK;
}

Status DeIntQueue(IntQueue *pq,int *pe)
{
	if(pq->front==pq->rear)
		return ERROR;
	*pe=(pq->base)[pq->front];
	pq->front=addone(pq->front,pq->size);
	return OK;
}

Status GetIntQueueFront(IntQueue *pq,int *pe)
{
	if(pq->front==pq->rear)
		return ERROR;
	*pe=(pq->base)[pq->front];
	return OK;
}

Bool IsIntQueueEmpty(IntQueue *pq)
{
 return pq->front==pq->rear;
}